package com.jingxuan.config;

import com.jingxuan.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 安全配置类（拦截器注册）
 */
@Configuration
public class SecurityConfig implements WebMvcConfigurer {

    @Autowired
    private AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/auth/login", // 登录接口
                        "/users", // 注册接口
                        "/products/**", // 商品查询接口（部分需要登录的会在controller中校验）
                        "/files/**", // 文件上传接口
                        "/uploads/**", // 静态资源
                        "/error",
                        "/actuator/**"); // 健康检查等监控接口
    }
}
